package nio.bytebuffer;

import java.nio.ByteBuffer;

public class Get {

    public static void main(String[] args) {

        byte[] byteArrayIn = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };
        ByteBuffer bytebuffer = ByteBuffer.wrap(byteArrayIn);
        byte[] byteArrayOut = new byte[5];
        while (bytebuffer.hasRemaining()) {
            int readLength = Math.min(bytebuffer.remaining(), byteArrayOut.length);
            bytebuffer.get(byteArrayOut, 0, readLength);
            for (int i = 0; i < readLength; i++) {
                System.out.print(byteArrayOut[i] + " ");
            }
            System.out.println();
        }

    }

}
